package rules.tree;

import java.util.Iterator;
import java.util.List;

import org.jdom.Element;

public class Context {

	private Element el;
        private Restriction restBody;
        private Restriction restHead;
	
	public Context(Element el) {
		this.el = el;
	}

        public Context(){
            el = new Element("context");
        }

        public void setRestrictionBody(Restriction rb){
            restBody=rb;
            el.addContent(rb.getElement());
        }

        public void setRestrictionHead(Restriction rh){
            restHead=rh;
            el.addContent(rh.getElement());
        }

	public Restriction getRestriction() {
		List temp = el.getChildren();
		Iterator it = temp.iterator();
		Element el_temp;
		Restriction r = null;
		while (it.hasNext()) {
			el_temp = (Element) it.next();
			if(el_temp.getName().equals("restrictionBody"))
				r = new Restriction(el_temp,0); //0 para body, 1 para head
			else r = new Restriction(el_temp,1);
		}
		return r;
	}

        public Restriction getRestrictionHead() {
		List temp = el.getChildren();
		Iterator it = temp.iterator();
		Element el_temp;
		Restriction r = null;
		while (it.hasNext()) {
			el_temp = (Element) it.next();
			if(el_temp.getName().equals("restrictionBody"))
				r = new Restriction(el_temp,0); //0 para body, 1 para head
			else r = new Restriction(el_temp,1);
		}
		return r;
	}

        public Restriction getRestrictionBody() {
		List temp = el.getChildren();
		Iterator it = temp.iterator();
		Element el_temp;
		Restriction r = null;
		while (it.hasNext()) {
			el_temp = (Element) it.next();
			if(el_temp.getName().equals("restrictionBody"))
				r = new Restriction(el_temp,0); //0 para body, 1 para head
			else r = new Restriction(el_temp,1);
		}
		return r;
	}

        public Element getElement(){
            return el;
        }

}
